<template>
	<Home ref="home" singPage></Home>
</template>

<script>
// import actLog from '@/components/modelParser/libs/actLog.js';
import Home from '@/components/modelParser/Home.vue';
import getCurrentUri from '@/components/modelParser/libs/getCurrentUri.js';
import getSharePath from '@/components/modelParser/libs/getSharePath.js';
import getAppInfo from '@/components/modelParser/libs/getAppInfo.js';
import getPageJson from '@/components/modelParser/libs/getPageJson.js';
import projectInfo from '@/components/modelParser/projectInfo.js';
// #ifdef H5
// 用于H5端预览页面----start----
// import getAppInfo_prev from '@/components/modelParser/libs/getAppInfo_prev.js';
// import getSearchParam from '@/components/modelParser/libs/getSearchParam.js';
// 用于H5端预览页面----end----
// #endif
export default {
	components: { Home },
	data() {
		return {
			pageData: {
				conData: [],
				appMenus: []
			},
			pageId: '',
			options: {},
			canDoOnshow: false
		};
	},
	provide(){
		return {
			options: ()=>this.options
		}
	},
	onShow() {
		if(this.canDoOnshow){
			this.$refs.home.pageState('show');
		}
	},
	onLoad(options) {
		this.options = options;
		this.pageId = options.pageId || '';
		// #ifdef H5
		// 用于H5端预览页面----start----
		// var search = getSearchParam()
		// if (search.timestamp && new Date().getTime() - search.timestamp * 1 > 1000 * 60 * 10) {
		// 	uni.showToast({
		// 		title: '链接已失效',
		// 		icon: 'none'
		// 	});
		// 	return;
		// }
		// this.$u.vuex('$tag', search.tag);
		// this.$u.vuex('$version', search.version);
		// this.$u.vuex('$prevMode', true);
		// getAppInfo_prev().then(()=>{
		// 	this.getPageData();
		// })
		// return
		// 用于H5端预览页面----end----
		// #endif
		getAppInfo().then(()=>{
			this.getPageData();
		},()=>{
			setTimeout(()=>{
				uni.showToast({
					title: '加载项目资源失败',
					icon: 'none'
				});
			})
		}).finally(() => {
			uni.hideLoading();
		})
	},
	methods: {
		getPageData() {
			getPageJson(this.pageId,'2').then(page=>{
				uni.stopPullDownRefresh()
				this.initHomePage(0,page)
			})
		},
		initHomePage(index,page){
			// 更新页面，并计算页面样式
			this.pageData.conData.splice(index,1,page);
			// #ifdef MP-TOUTIAO
			this.$nextTick(()=>{
			// #endif
			this.$refs.home.pageData.conData = this.pageData.conData;
			this.$refs.home.pageInit(index)
			this.canDoOnshow = true
			// #ifdef MP-TOUTIAO
			})
			// #endif
		},
	},
	onPullDownRefresh() {
		this.getPageData();
	},
	onShareAppMessage(res) {
		var path, imageUrl = '';
		if (res.from === 'button') {
			var shareInfo = res.target.dataset.share;
			path = getSharePath(shareInfo, 'singlePage', this.pageData, this.options);
			console.log('path',path);
			imageUrl = shareInfo.image || ''
		} else {
			path = getCurrentUri();
		}
		// var nowPageId = '',source = 'singlePage'
		// if(source === 'indexPage'){
		// 	var originSelectIndex = this.pageData.appMenus[0].common.originSelectIndex;
		// 	nowPageId = this.pageData.appMenus[0].common.links[originSelectIndex].pageId;
		// } else if (source === 'singlePage'){
		// 	nowPageId = this.pageData.conData[0].cid
		// }
		// actLog({
		// 	shareLockCycle: 24,
		// 	pageCode: nowPageId,
		// 	itemType: 'share',
		// 	itemCode: '2',
		// 	itemName: '通用分享',
		// 	actCode: '',
		// 	themeCode: '',
		// 	withLoc: true,
		// },{},'',path)
		console.log('分享的路径',path);
		return {
			title: projectInfo.proName,
			path: path,
			imageUrl
		};
	},
	onShareTimeline() {
		return {
			title: projectInfo.proName
		};
	}
};
</script>